import { Body, Controller, Delete, Get, Param, Patch, Post, UseGuards } from '@nestjs/common';
import { RolePermissionService } from './role-permission.service';
import { CreateRolePermissionDto } from './dto/create-role-permission.dto';
import { UpdateRolePermissionDto } from './dto/update-role-permission.dto';
import { ApiBearerAuth, ApiHeader, ApiOperation, ApiTags } from '@nestjs/swagger';
import { AuthGuard } from '@nestjs/passport';

@ApiBearerAuth() // 需要token
@UseGuards(AuthGuard('jwt'))
@ApiTags('用户分配权限')
@ApiHeader({
	name: 'authoriation',
	required: true,
	description: 'token',
})
@Controller({
	path: 'rolePermission',
	version: '1',
})
export class RolePermissionController {
	constructor(private readonly rolePermissionService: RolePermissionService) {}

	@ApiOperation({
		tags: ['给角色分配权限'],
		description: '给角色分配权限',
	})
	@Post('/grantPermissionsToRole')
	grantPermissionsToRole(@Body() createRolePermissionDto: CreateRolePermissionDto) {
		return this.rolePermissionService.grantPermissionsToRole(createRolePermissionDto);
	}

	@Get('/findRolePermissionsMenus/:roleId')
	findRolePermissions(@Param('roleId') roleId: number) {
		return this.rolePermissionService.findRolePermissionsMenus(roleId);
	}

	@Post()
	create(@Body() createRolePermissionDto: CreateRolePermissionDto) {
		return this.rolePermissionService.create(createRolePermissionDto);
	}

	@Get()
	findAll() {
		return this.rolePermissionService.findAll();
	}

	@Get(':id')
	findOne(@Param('id') id: string) {
		return this.rolePermissionService.findOne(+id);
	}

	@Patch(':id')
	update(@Param('id') id: string, @Body() updateRolePermissionDto: UpdateRolePermissionDto) {
		return this.rolePermissionService.update(+id, updateRolePermissionDto);
	}

	@Delete(':id')
	remove(@Param('id') id: string) {
		return this.rolePermissionService.remove(+id);
	}
}
